#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        int n;
        int a[200010];
        cin>>n;
        int maxn=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            maxn=max(maxn,a[i]);
        }
        int sum=0;
        if(n==1) cout<<0<<endl;
        else if(n==2){
            if(a[1]==a[2]) cout<<a[1]<<endl;
            else cout<<0<<endl;
        }else if(n==3){
            if(a[1]==a[2]||a[1]==a[3]) cout<<a[1]<<endl;
            else if(a[2]==a[3]) cout<<a[2]<<endl;
        }else{
            cout<<maxn<<endl;
        }
    }
    return 0;
}
